package com.atguigu;

public class SingletonDemo {
    private static volatile SingletonDemo instance=null;
    private  SingletonDemo(){
 System.err.println( Thread.currentThread().getName() +"我是构造方法");
    }
    public static  SingletonDemo getInstance(){
        if(instance==null){
            synchronized(SingletonDemo.class)
            {
                if(instance==null){
                    instance=new SingletonDemo();
                }
            }

        }
        return instance;
    }
    public static void main(String[] args) {
//        //main线程的操作动作
//        System.err.println(SingletonDemo.getInstance()==SingletonDemo.getInstance());
//        System.err.println(SingletonDemo.getInstance()==SingletonDemo.getInstance());
//        System.err.println(SingletonDemo.getInstance()==SingletonDemo.getInstance());
        //
        for (int i = 0; i <10000000 ; i++) {
            new Thread(()->{
                //SingletonDemo.getInstance();
               //stem.err.println(SingletonDemo.getInstance());
            },String.valueOf(i+1)).start();
            System.err.println("asasas");
        }

    }
}
